﻿Imports System.Data.SqlClient
Public Class FormCategoryEditor

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        If cmbTypeName.Text.Trim() = "" Then
            MsgBox("Please Select Typ Name")
            cmbTypeName.Select()
            Exit Sub
        End If
        If txtCategoryName.Text.Trim() = "" Then
            MsgBox("Please Input Category Name !!!")
            txtCategoryName.Focus()
            Exit Sub
        End If
        'Cmd.Parameters("@TypeName") = cmbTypeName.Text
        Cmd.Parameters("@CategoryName") = txtCategoryName.Text
        If Me.txtCategoryId.Text = "" Then
            Cmd.ExecuteNonQuery("INSERT INTO Category VALUES (@CategoryName,1)")
        Else
            Cmd.Parameters("@CategoryId") = txtCategoryId.Text
            Cmd.ExecuteNonQuery("UPDATE Category SET CategoryName=@CategoryName WHERE CategoryId=@CategoryId")
        End If
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub
    Public Sub LoadType()
        Dim dt = Cmd.ExecuteDataTable("SELECT * FROM Type")
        cmbTypeName.DisplayMember = "TypeName"
        cmbTypeName.ValueMember = "TypeName"
        'cmbTypeId.DisplayMember = "TypeId"
        cmbTypeName.DataSource = dt
    End Sub
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()
        LoadType()
    End Sub
    Private Sub FormCategoryEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class